package com.manage.system.web.controller;

import com.manage.common.core.enums.CommonEnum;
import com.manage.common.core.result.JsonResult;
import com.manage.system.api.dto.OauthClientDetailsDto;
import com.manage.system.api.request.client.OauthClientParam;
import com.manage.system.api.service.IOauthClientDetailsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhangqing
 * @version V1.0
 * @description 授权客户端控制层
 * @date 10/3/2021 9:50 AM
 */
@RestController
@RequestMapping("/client")
@AllArgsConstructor
@Api(tags = "Oauth2客户端管理接口", value = "OauthClientController")
public class OauthClientController {

    private final IOauthClientDetailsService oauthClientDetailsService;

    @ApiOperation("分页获取客户端列表")
    @PostMapping("/getListPage")
    public JsonResult getListPage(@RequestBody OauthClientParam oauthClientParam) {
        return oauthClientDetailsService.findListPage(oauthClientParam);
    }

    @ApiOperation("更新客户端")
    @PutMapping("/update")
    public JsonResult edit(@RequestBody OauthClientDetailsDto oauthClientDetailsDto) {
        return oauthClientDetailsService.updateOauthClientDetail(oauthClientDetailsDto);
    }

    @ApiOperation("根据客户端id删除客户端")
    @DeleteMapping("/delete/{clientId}")
    public JsonResult delete(@PathVariable String clientId) {
        return oauthClientDetailsService.deleteById(clientId);
    }

    @ApiOperation("保存客户端")
    @PostMapping("/save")
    public JsonResult save(@RequestBody OauthClientDetailsDto oauthClientDetailsDto) {
        return oauthClientDetailsService.save(oauthClientDetailsDto);
    }

    @ApiOperation("根据客户端id获取客户端详情信息")
    @GetMapping("/find-one/{clientId}")
    public JsonResult findOne(@PathVariable("clientId") String clientId) {
        return oauthClientDetailsService.findByClientId(clientId);
    }
}
